//
//  QJBasicViewController.m
//  QuanJieShopProject
//
//  Created by apple on 2018/1/30.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJBasicViewController.h"
#import "QJLoginVC.h"
//数据为空的控件
#import "UIScrollView+EmptyDataSet.h"
@interface QJBasicViewController ()<DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>

@end

@implementation QJBasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    

}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self networkStateAction];
    //将控件的布局偏移到导航栏下面
//    self.navigationController.navigationBar.translucent = NO;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alertLoginViewAction) name:@"alertLoginView" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    // YF 4.19 之前是在viewDidLoad注册,但是没有销毁
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"alertLoginView" object:nil];
}

#pragma mark -- 网络状态提示
- (void)networkStateAction{
    if ([YFGlobalTool getNetworkType] == NetworkType_Offline) {
//        [MBPHUD showAlertWithTitle:@"请检查您的网络状态" duration:2.0f];
    }
}
- (void)setNavAlpha:(BOOL)alpha{
    if (alpha) {
        //透明
        //设置导航栏背景图片为一个空的image，这样就透明了
        [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
        //去掉透明后导航栏下边的黑边
        [self.navigationController.navigationBar setShadowImage:[UIImage new]];
        //隐藏导航栏
//        self.navigationController.navigationBarHidden = YES;
    }else{
        //不透明
        //如果不想让其他页面的导航栏变为透明 需要重置
        [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setShadowImage:nil];
        //显示导航栏
//        self.navigationController.navigationBarHidden = NO;
    }
}
#pragma mark -- 弹出登录界面
- (void)alertLoginViewAction{
    
    KMyLog(@"======弹框  即将弹出");
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还没有登录，或者登录状态已经失效，您是否现在需要重新登录?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // YF4.19
//        [self.tabBarController setSelectedIndex:0];
        QJLoginVC *VC = [[QJLoginVC alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"随便看看" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        // YF4.19
//        [self.tabBarController setSelectedIndex:0];
    }];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -- DZNEmptyDataSetSource
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIImage imageNamed:@"noDataImage"];
}
#pragma mark -- DZNEmptyDataSetDelegate
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
    return YES;
}

@end
